import Vue from 'vue'
import cookie from 'js-cookie'
import Router from 'vue-router'
import Login from './components/Login.vue'
import Home from './components/Home.vue'
import User from '@/views/user/User'
import Department from '@/views/department/department'
import Directive from '@/views/directive/directive'
import Schedule from '@/views/schedule/schedule'
import Welcome from './components/Welcome.vue'
import RegistLevel from '@/views/registLevel/registLevel'
import SaveRregistLevel from '@/views/registLevel/saveRregistLevel'
import Settlecategory from '@/views/settlecategory/settlecategory'
import DiseCategory from '@/views/disease/diseCategory'
import Disease from '@/views/disease/disease'
import Fmeditem from '@/views/fmeditem/fmeditem'
import AddFmeditem from '@/views/fmeditem/addFmeditem'
import SaveUser from '@/views/user/saveUser'
Vue.use(Router)


const router = new Router({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/user', component: User },
        { path: '/user/saveUser', component: SaveUser },    
        { path: '/department', component: Department },
        { path: '/directive', component: Directive },
        { path: '/schedule', component: Schedule },
        { path: '/registlevel', component: RegistLevel},
        { path: '/registlevel/saverregistlevel', component: SaveRregistLevel},
        { path: '/settlecategory', component: Settlecategory},
        { path: '/disease', component: Disease},
        { path: '/diseCategory', component: DiseCategory},
        { path: '/fmeditem', component: Fmeditem},
        { path: '/fmeditem/addFmeditem', component: AddFmeditem} 
             
      ]
    }
  ]
})

// // 挂载路由导航守卫
router.beforeEach((to, from, next) => {

  if (to.path === '/login') return next()
  // 获取token
  const tokenStr = cookie.get('his_token');
  if (!tokenStr) return next('/login')
  next()
})

export default router
